package com.glsc.ngateway.common.base.domain.mysql.gateway.platform.webfield;

import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.SQLDeleteAll;
import org.hibernate.annotations.Where;

import javax.persistence.*;
import java.io.Serializable;
import java.util.List;

/**
 * @author zhengyr
 * @date 2024/1/29-12:47
 * 前端字段条目属性配置
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
@Entity
@Where(clause = "deleted = 0")
@SQLDelete(sql = "update t_gw_web_field_config set deleted = UNIX_TIMESTAMP(NOW()) where id=?")
@SQLDeleteAll(sql = "update t_gw_web_field_config set deleted = UNIX_TIMESTAMP(NOW()) where id=?")
@Table(name = "t_gw_web_field_config")
public class WebFieldItem implements Serializable {

    @ApiModelProperty(value = "id")
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Integer id;

    @ApiModelProperty(value = "关联的主表有业务含义的唯一业务key")
    @Column(name = "main_key", columnDefinition = "VARCHAR(50) NOT NULL COMMENT '关联的主表有业务含义的唯一业务key' ")
    private String mainKey;

    @ApiModelProperty(value = "排序序号")
    @Column(name = "seq", columnDefinition = "INT default 0 COMMENT '字段排序序号'")
    private Integer seq;

    @ApiModelProperty(value = "字段中文名")
    @Column(name = "title", columnDefinition = "VARCHAR(50) NOT NULL COMMENT '字段中文名'")
    private String title;

    @ApiModelProperty(value = "字段英文名")
    @Column(name = "field_code", columnDefinition = "VARCHAR(50) NOT NULL COMMENT '字段英文名'")
    private String fieldCode;

    //当某字段是列表类型时，与其下的列表字段关联
    @ApiModelProperty(value = "父级字段英文名")
    @Column(name = "parent_field_code", columnDefinition = "VARCHAR(50) COMMENT '父级字段英文名'")
    private String parentFieldCode;

    @ApiModelProperty(value = "字段类型")
    @Column(name = "field_type", columnDefinition = "VARCHAR(50) NOT NULL COMMENT '字段类型'")
    private String fieldType;

    @ApiModelProperty(value = "是否做查询条件（如有）")
    @Column(name = "is_filter", columnDefinition = "CHAR(1) COMMENT '是否做查询条件（如有）'")
    private String isFilter;

    @ApiModelProperty(value = "新增/修改时是否必填（如有）")
    @Column(name = "is_required", columnDefinition = "CHAR(1) COMMENT '新增修改时是否必填（如有）'")
    private String isRequired;

    @ApiModelProperty(value = "单位（如有）")
    @Column(name = "addon_after", columnDefinition = "VARCHAR(10) COMMENT '单位（如有）'")
    private String addonAfter;

    @ApiModelProperty(value = "精度（如有）")
    @Column(name = "num_precision", columnDefinition = "TINYINT COMMENT '精度（如有）'")
    private byte numPrecision;

    @ApiModelProperty(value = "人员类别（如有）")
    @Column(name = "person_type", columnDefinition = "VARCHAR(10) COMMENT '人员类别（如有）'")
    private String personType;

    @ApiModelProperty(value = "部门类别（如有）")
    @Column(name = "department_type", columnDefinition = "VARCHAR(10) COMMENT '部门类别（如有）'")
    private String departmentType;

    @ApiModelProperty(value = "是否多选（如有）")
    @Column(name = "is_multiple", columnDefinition = "CHAR(1) COMMENT '是否多选（如有）'")
    private String isMultiple;

    @ApiModelProperty(value = "字典code（如有）")
    @Column(name = "dict_code", columnDefinition = "VARCHAR(50) COMMENT '字典code（如有）'")
    private String dictCode;

    @Builder.Default
    @Column(name = "deleted", columnDefinition = "bigint NOT NULL default 0")
    private Long deleted = 0L;

    @Transient
    @ApiModelProperty(value = "可编辑列表类型的字段配置")
    private List<WebFieldItem> editFieldList;
}
